package com.ngc.mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ngc.mall.domain.AdminRoleDomain;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<AdminRoleDomain> {

    @Select("select menu_id from role_menu where role_id = #{roleId}")
    List<Long> getMenuByRoleId(Long roleId);

    @Insert({
            "<script>",
            "insert into role_menu(role_id,menu_id) values",
            "<foreach collection='permissions' item='item'  separator=',' >",
            "(#{roleId},#{item})",
            "</foreach>",
            "</script>"
    })
    Boolean insertMenuByRoleId(List<Long> permissions,Long roleId);

    @Delete("delete from role_menu where role_id=#{roleId}")
    Boolean removeMenuByRoleId(Long roleId);
}
